//
//  WCNTableViewController.m
//  WCN
//
//  Created by 杨鑫 on 15/6/1.
//  Copyright (c) 2015年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCNTableViewController.h"
//
#import "WCButton.h"
//
#import "UINavigationItem+Offset.h"

@interface WCNTableViewController ()

@property (weak, nonatomic) UILabel *titleLabel;

@end

@implementation WCNTableViewController

- (instancetype)init
{
    return [self initWithStyle:UITableViewStylePlain];
}

- (instancetype)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        //need pageBack, 因为TableViewController不会在一级目录，所以直接加上返回键
        WCButton *backButton = [WCButton backButton];
        [backButton addTarget:self action:@selector(pageBack) forControlEvents:UIControlEventTouchUpInside];
        [self.navigationItem addLeftBarButtonItem:backButton];
    }
    return self;
}

#pragma mark - Target Actions

- (void)pageBack
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Setter

- (void)setTitle:(NSString *)title
{
    [super setTitle:title];
    
    if (self.titleLabel) {
        self.titleLabel.text = title;
    } else {
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 160, 30)];
        titleLabel.text = title;
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont boldSystemFontOfSize:20];
        
        self.navigationItem.titleView = titleLabel;
        self.titleLabel = titleLabel;
    }
}

@end
